home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / Net / FTP.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  32.9 KB  |  1,491 lines

  1.  
  2. package Net::FTP;
  3.  
  4. require 5.001;
  5.  
  6. use strict;
  7. use vars qw(@ISA $VERSION);
  8. use Carp;
  9.  
  10. use Socket 1.3;
  11. use IO::Socket;
  12. use Time::Local;
  13. use Net::Cmd;
  14. use Net::Config;
  15.  
  16. $VERSION = do { my @r=(q$Revision: 2.21 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  17. @ISA     = qw(Exporter Net::Cmd IO::Socket::INET);
  18.  
  19. sub new
  20. {
  21.  my $pkg  = shift;
  22.  my $peer = shift;
  23.  my %arg  = @_; 
  24.  
  25.  my $host = $peer;
  26.  my $fire = undef;
  27.  
  28.  unless(defined inet_aton($peer)) # GMB: Should I use Net::Ping here ??
  29.   {
  30.    $fire = $ENV{FTP_FIREWALL}
  31.     || $arg{Firewall}
  32.     || $NetConfig{ftp_firewall}
  33.     || undef;
  34.  
  35.    if(defined $fire)
  36.     {
  37.      $peer = $fire;
  38.      delete $arg{Port};
  39.     }
  40.   }
  41.  
  42.  my $ftp = $pkg->SUPER::new(PeerAddr => $peer, 
  43.                 PeerPort => $arg{Port} || 'ftp(21)',
  44.                 Proto    => 'tcp',
  45.                 Timeout  => defined $arg{Timeout}
  46.                         ? $arg{Timeout}
  47.                         : 120
  48.                ) or return undef;
  49.  
  50.  ${*$ftp}{'net_ftp_host'}     = $host;        # Remote hostname
  51.  ${*$ftp}{'net_ftp_type'}     = 'A';        # ASCII/binary/etc mode
  52.  
  53.  ${*$ftp}{'net_ftp_firewall'} = $fire
  54.     if(defined $fire);
  55.  
  56.  ${*$ftp}{'net_ftp_passive'} = int
  57.     exists $arg{Passive}
  58.         ? $arg{Passive}
  59.         : exists $ENV{FTP_PASSIVE}
  60.         ? $ENV{FTP_PASSIVE}
  61.         : defined $fire
  62.             ? $NetConfig{ftp_ext_passive}
  63.             : $NetConfig{ftp_int_passive};    # Whew! :-)
  64.  
  65.  $ftp->autoflush(1);
  66.  
  67.  $ftp->debug(exists $arg{Debug} ? $arg{Debug} : undef);
  68.  
  69.  unless ($ftp->response() == CMD_OK)
  70.   {
  71.    $ftp->SUPER::close();
  72.    undef $ftp;
  73.   }
  74.  
  75.  $ftp;
  76. }
  77.  
  78.  
  79. sub quit
  80. {
  81.  my $ftp = shift;
  82.  
  83.  $ftp->_QUIT
  84.     && $ftp->close;
  85. }
  86.  
  87. sub close
  88. {
  89.  my $ftp = shift;
  90.  
  91.  ref($ftp) 
  92.     && defined fileno($ftp)
  93.     && $ftp->SUPER::close;
  94. }
  95.  
  96. sub DESTROY { shift->close }
  97.  
  98. sub ascii  { shift->type('A',@_); }
  99. sub binary { shift->type('I',@_); }
  100.  
  101. sub ebcdic
  102. {
  103.  carp "TYPE E is unsupported, shall default to I";
  104.  shift->type('E',@_);
  105. }
  106.  
  107. sub byte
  108. {
  109.  carp "TYPE L is unsupported, shall default to I";
  110.  shift->type('L',@_);
  111. }
  112.  
  113.  
  114. sub quot
  115.  my $ftp = shift;
  116.  my $cmd = shift;
  117.  
  118.  $ftp->command( uc $cmd, @_);
  119.  $ftp->response();
  120. }
  121.  
  122. sub mdtm
  123. {
  124.  my $ftp  = shift;
  125.  my $file = shift;
  126.  
  127.  $ftp->_MDTM($file) && $ftp->message =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
  128.     ? timegm($6,$5,$4,$3,$2-1,$1 - 1900)
  129.     : undef;
  130. }
  131.  
  132. sub size
  133. {
  134.  my $ftp  = shift;
  135.  my $file = shift;
  136.  
  137.  $ftp->_SIZE($file)
  138.     ? ($ftp->message =~ /(\d+)/)[0]
  139.     : undef;
  140. }
  141.  
  142. sub login
  143. {
  144.  my($ftp,$user,$pass,$acct) = @_;
  145.  my($ok,$ruser);
  146.  
  147.  unless (defined $user)
  148.   {
  149.    require Net::Netrc;
  150.  
  151.    my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'});
  152.  
  153.    ($user,$pass,$acct) = $rc->lpa()
  154.     if ($rc);
  155.   }
  156.  
  157.  $user ||= "anonymous";
  158.  $ruser = $user;
  159.  
  160.  if(defined ${*$ftp}{'net_ftp_firewall'})
  161.   {
  162.    $user .= "@" . ${*$ftp}{'net_ftp_host'};
  163.   }
  164.  
  165.  $ok = $ftp->_USER($user);
  166.  
  167.  $ok = $ftp->response()
  168.     if($ok == CMD_OK && $ftp->code == 220 && $user =~ /\@/);
  169.  
  170.  if ($ok == CMD_MORE)
  171.   {
  172.    unless(defined $pass)
  173.     {
  174.      require Net::Netrc;
  175.  
  176.      my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'}, $ruser);
  177.  
  178.      ($ruser,$pass,$acct) = $rc->lpa()
  179.     if ($rc);
  180.  
  181.      $pass = "-" . ($^O =~ /mswin32/i ? $ENV{'USERNAME'} :
  182.                         (getpwuid($>))[0]) . "@" 
  183.         if (!defined $pass && $ruser =~ /^anonymous/o);
  184.     }
  185.  
  186.    $ok = $ftp->_PASS($pass || "");
  187.   }
  188.  
  189.  $ok = $ftp->_ACCT($acct || "")
  190.     if ($ok == CMD_MORE);
  191.  
  192.  $ftp->authorize()
  193.     if($ok == CMD_OK && defined ${*$ftp}{'net_ftp_firewall'});
  194.  
  195.  $ok == CMD_OK;
  196. }
  197.  
  198. sub authorize
  199. {
  200.  @_ >= 1 || @_ <= 3 or croak 'usage: $ftp->authorize( [AUTH [, RESP]])';
  201.  
  202.  my($ftp,$auth,$resp) = @_;
  203.  
  204.  unless(defined $resp)
  205.   {
  206.    require Net::Netrc;
  207.  
  208.    $auth ||= ($^O =~ /mswin32/i ? $ENV{'USERNAME'} : (getpwuid($>))[0]);
  209.  
  210.    my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'}, $auth)
  211.         || Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
  212.  
  213.    ($auth,$resp) = $rc->lpa()
  214.      if($rc);
  215.   }
  216.  
  217.  my $ok = $ftp->_AUTH($auth || "");
  218.  
  219.  $ok = $ftp->_RESP($resp || "")
  220.     if ($ok == CMD_MORE);
  221.  
  222.  $ok == CMD_OK;
  223. }
  224.  
  225. sub rename
  226. {
  227.  @_ == 3 or croak 'usage: $ftp->rename(FROM, TO)';
  228.  
  229.  my($ftp,$from,$to) = @_;
  230.  
  231.  $ftp->_RNFR($from)
  232.     && $ftp->_RNTO($to);
  233. }
  234.  
  235. sub type
  236. {
  237.  my $ftp = shift;
  238.  my $type = shift;
  239.  my $oldval = ${*$ftp}{'net_ftp_type'};
  240.  
  241.  return $oldval
  242.     unless (defined $type);
  243.  
  244.  return undef
  245.     unless ($ftp->_TYPE($type,@_));
  246.  
  247.  ${*$ftp}{'net_ftp_type'} = join(" ",$type,@_);
  248.  
  249.  $oldval;
  250. }
  251.  
  252. my($TELNET_IAC,$TELNET_IP,$TELNET_DM) = (255,244,242);
  253.  
  254. sub abort
  255. {
  256.  my $ftp = shift;
  257.  
  258.  send($ftp,pack("CC",$TELNET_IAC,$TELNET_IP),0);
  259.  send($ftp,pack("C", $TELNET_IAC),MSG_OOB);
  260.  send($ftp,pack("C", $TELNET_DM),0);
  261.  
  262.  $ftp->command("ABOR");
  263.  
  264.  defined ${*$ftp}{'net_ftp_dataconn'}
  265.     ? ${*$ftp}{'net_ftp_dataconn'}->close()
  266.     : $ftp->response();
  267.  
  268.  $ftp->response()
  269.     if $ftp->status == CMD_REJECT;
  270.  
  271.  $ftp->status == CMD_OK;
  272. }
  273.  
  274. sub get
  275. {
  276.  my($ftp,$remote,$local,$where) = @_;
  277.  
  278.  my($loc,$len,$buf,$resp,$localfd,$data);
  279.  local *FD;
  280.  
  281.  $localfd = ref($local) ? fileno($local)
  282.             : undef;
  283.  
  284.  ($local = $remote) =~ s#^.*/##
  285.     unless(defined $local);
  286.  
  287.  ${*$ftp}{'net_ftp_rest'} = $where
  288.     if ($where);
  289.  
  290.  delete ${*$ftp}{'net_ftp_port'};
  291.  delete ${*$ftp}{'net_ftp_pasv'};
  292.  
  293.  $data = $ftp->retr($remote) or
  294.     return undef;
  295.  
  296.  if(defined $localfd)
  297.   {
  298.    $loc = $local;
  299.   }
  300.  else
  301.   {
  302.    $loc = \*FD;
  303.  
  304.    unless(($where) ? open($loc,">>$local") : open($loc,">$local"))
  305.     {
  306.      carp "Cannot open Local file $local: $!\n";
  307.      $data->abort;
  308.      return undef;
  309.     }
  310.   }
  311.  
  312.  if($ftp->type eq 'I' && !binmode($loc))
  313.   {
  314.    carp "Cannot binmode Local file $local: $!\n";
  315.    $data->abort;
  316.    return undef;
  317.   }
  318.  
  319.  $buf = '';
  320.  
  321.  do
  322.   {
  323.    $len = $data->read($buf,1024);
  324.   }
  325.  while($len > 0 && syswrite($loc,$buf,$len) == $len);
  326.  
  327.  close($loc)
  328.     unless defined $localfd;
  329.  
  330.  $data->close(); # implied $ftp->response
  331.  
  332.  return $local;
  333. }
  334.  
  335. sub cwd
  336. {
  337.  @_ == 2 || @_ == 3 or croak 'usage: $ftp->cwd( [ DIR ] )';
  338.  
  339.  my($ftp,$dir) = @_;
  340.  
  341.  $dir ||= "/";
  342.  
  343.  $dir eq ".."
  344.     ? $ftp->_CDUP()
  345.     : $ftp->_CWD($dir);
  346. }
  347.  
  348. sub cdup
  349. {
  350.  @_ == 1 or croak 'usage: $ftp->cdup()';
  351.  $_[0]->_CDUP;
  352. }
  353.  
  354. sub pwd
  355. {
  356.  @_ == 1 || croak 'usage: $ftp->pwd()';
  357.  my $ftp = shift;
  358.  
  359.  $ftp->_PWD();
  360.  $ftp->_extract_path;
  361. }
  362.  
  363. sub rmdir
  364. {
  365.  @_ == 2 || croak 'usage: $ftp->rmdir( DIR )';
  366.  
  367.  $_[0]->_RMD($_[1]);
  368. }
  369.  
  370. sub mkdir
  371. {
  372.  @_ == 2 || @_ == 3 or croak 'usage: $ftp->mkdir( DIR [, RECURSE ] )';
  373.  
  374.  my($ftp,$dir,$recurse) = @_;
  375.  
  376.  $ftp->_MKD($dir) || $recurse or
  377.     return undef;
  378.  
  379.  my $path = $dir;
  380.  
  381.  unless($ftp->ok)
  382.   {
  383.    my @path = split(m#(?=/+)#, $dir);
  384.  
  385.    $path = "";
  386.  
  387.    while(@path)
  388.     {
  389.      $path .= shift @path;
  390.  
  391.      $ftp->_MKD($path);
  392.      $path = $ftp->_extract_path($path);
  393.  
  394.      last
  395.         unless $ftp->ok || $ftp->code == 521 || $ftp->code == 550;
  396.     }
  397.   }
  398.  
  399.  $ftp->_extract_path($path);
  400. }
  401.  
  402. sub delete
  403. {
  404.  @_ == 2 || croak 'usage: $ftp->delete( FILENAME )';
  405.  
  406.  $_[0]->_DELE($_[1]);
  407. }
  408.  
  409. sub put        { shift->_store_cmd("stor",@_) }
  410. sub put_unique { shift->_store_cmd("stou",@_) }
  411. sub append     { shift->_store_cmd("appe",@_) }
  412.  
  413. sub nlst { shift->_data_cmd("NLST",@_) }
  414. sub list { shift->_data_cmd("LIST",@_) }
  415. sub retr { shift->_data_cmd("RETR",@_) }
  416. sub stor { shift->_data_cmd("STOR",@_) }
  417. sub stou { shift->_data_cmd("STOU",@_) }
  418. sub appe { shift->_data_cmd("APPE",@_) }
  419.  
  420. sub _store_cmd 
  421. {
  422.  my($ftp,$cmd,$local,$remote) = @_;
  423.  my($loc,$sock,$len,$buf,$localfd);
  424.  local *FD;
  425.  
  426.  $localfd = ref($local) ? fileno($local)
  427.             : undef;
  428.  
  429.  unless(defined $remote)
  430.   {
  431.    croak 'Must specify remote filename with stream input'
  432.     if defined $localfd;
  433.  
  434.    ($remote = $local) =~ s%.*/%%;
  435.   }
  436.  
  437.  if(defined $localfd)
  438.   {
  439.    $loc = $local;
  440.   }
  441.  else
  442.   {
  443.    $loc = \*FD;
  444.  
  445.    unless(open($loc,"<$local"))
  446.     {
  447.      carp "Cannot open Local file $local: $!\n";
  448.      return undef;
  449.     }
  450.   }
  451.  
  452.  if($ftp->type eq 'I' && !binmode($loc))
  453.   {
  454.    carp "Cannot binmode Local file $local: $!\n";
  455.    return undef;
  456.   }
  457.  
  458.  delete ${*$ftp}{'net_ftp_port'};
  459.  delete ${*$ftp}{'net_ftp_pasv'};
  460.  
  461.  $sock = $ftp->_data_cmd($cmd, $remote) or 
  462.     return undef;
  463.  
  464.  while(1)
  465.   {
  466.    last unless $len = sysread($loc,$buf="",1024);
  467.  
  468.    unless($sock->write($buf,$len) == $len)
  469.     {
  470.      $sock->abort;
  471.      close($loc)
  472.     unless defined $localfd;
  473.      return undef;
  474.     }
  475.   }
  476.  
  477.  $sock->close();
  478.  
  479.  close($loc)
  480.     unless defined $localfd;
  481.  
  482.  ($remote) = $ftp->message =~ /unique file name:\s*(\S*)\s*\)/
  483.     if ('STOU' eq uc $cmd);
  484.  
  485.  return $remote;
  486. }
  487.  
  488. sub port
  489. {
  490.  @_ == 1 || @_ == 2 or croak 'usage: $ftp->port([PORT])';
  491.  
  492.  my($ftp,$port) = @_;
  493.  my $ok;
  494.  
  495.  delete ${*$ftp}{'net_ftp_intern_port'};
  496.  
  497.  unless(defined $port)
  498.   {
  499.  
  500.    ${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET->new(Listen    => 5,
  501.                                         Proto     => 'tcp',
  502.                                         LocalAddr => $ftp->sockhost, 
  503.                                        );
  504.   
  505.    my $listen = ${*$ftp}{'net_ftp_listen'};
  506.  
  507.    my($myport, @myaddr) = ($listen->sockport, split(/\./,$listen->sockhost));
  508.  
  509.    $port = join(',', @myaddr, $myport >> 8, $myport & 0xff);
  510.  
  511.    ${*$ftp}{'net_ftp_intern_port'} = 1;
  512.   }
  513.  
  514.  $ok = $ftp->_PORT($port);
  515.  
  516.  ${*$ftp}{'net_ftp_port'} = $port;
  517.  
  518.  $ok;
  519. }
  520.  
  521. sub ls  { shift->_list_cmd("NLST",@_); }
  522. sub dir { shift->_list_cmd("LIST",@_); }
  523.  
  524. sub pasv
  525. {
  526.  @_ == 1 or croak 'usage: $ftp->pasv()';
  527.  
  528.  my $ftp = shift;
  529.  
  530.  delete ${*$ftp}{'net_ftp_intern_port'};
  531.  
  532.  $ftp->_PASV && $ftp->message =~ /(\d+(,\d+)+)/
  533.     ? ${*$ftp}{'net_ftp_pasv'} = $1
  534.     : undef;    
  535. }
  536.  
  537. sub unique_name
  538. {
  539.  my $ftp = shift;
  540.  ${*$ftp}{'net_ftp_unique'} || undef;
  541. }
  542.  
  543.  
  544. sub lsl
  545. {
  546.  carp "Use of Net::FTP::lsl depreciated, use 'dir'"
  547.     if $^W;
  548.  goto &dir;
  549. }
  550.  
  551. sub authorise
  552. {
  553.  carp "Use of Net::FTP::authorise depreciated, use 'authorize'"
  554.     if $^W;
  555.  goto &authorize;
  556. }
  557.  
  558.  
  559.  
  560. sub _extract_path
  561. {
  562.  my($ftp, $path) = @_;
  563.  
  564.  $ftp->ok &&
  565.     $ftp->message =~ /(?:^|\s)\"(.*)\"(?:$|\s)/ &&
  566.     ($path = $1) =~ s/\"\"/\"/g;
  567.  
  568.  $path;
  569. }
  570.  
  571.  
  572. sub _dataconn
  573. {
  574.  my $ftp = shift;
  575.  my $data = undef;
  576.  my $pkg = "Net::FTP::" . $ftp->type;
  577.  
  578.  $pkg =~ s/ /_/g;
  579.  
  580.  delete ${*$ftp}{'net_ftp_dataconn'};
  581.  
  582.  if(defined ${*$ftp}{'net_ftp_pasv'})
  583.   {
  584.    my @port = split(/,/,${*$ftp}{'net_ftp_pasv'});
  585.  
  586.    $data = $pkg->new(PeerAddr => join(".",@port[0..3]),
  587.                      PeerPort => $port[4] * 256 + $port[5],
  588.                      Proto    => 'tcp'
  589.                     );
  590.   }
  591.  elsif(defined ${*$ftp}{'net_ftp_listen'})
  592.   {
  593.    $data = ${*$ftp}{'net_ftp_listen'}->accept($pkg);
  594.    close(delete ${*$ftp}{'net_ftp_listen'});
  595.   }
  596.  
  597.  if($data)
  598.   {
  599.    ${*$data} = "";
  600.    $data->timeout($ftp->timeout);
  601.    ${*$ftp}{'net_ftp_dataconn'} = $data;
  602.    ${*$data}{'net_ftp_cmd'} = $ftp;
  603.   }
  604.  
  605.  $data;
  606. }
  607.  
  608. sub _list_cmd
  609. {
  610.  my $ftp = shift;
  611.  my $cmd = uc shift;
  612.  
  613.  delete ${*$ftp}{'net_ftp_port'};
  614.  delete ${*$ftp}{'net_ftp_pasv'};
  615.  
  616.  my $data = $ftp->_data_cmd($cmd,@_);
  617.  
  618.  return undef
  619.     unless(defined $data);
  620.  
  621.  bless $data, "Net::FTP::A"; # Force ASCII mode
  622.  
  623.  my $databuf = '';
  624.  my $buf = '';
  625.  
  626.  while($data->read($databuf,1024))
  627.   {
  628.    $buf .= $databuf;
  629.   }
  630.  
  631.  my $list = [ split(/\n/,$buf) ];
  632.  
  633.  $data->close();
  634.  
  635.  wantarray ? @{$list}
  636.            : $list;
  637. }
  638.  
  639. sub _data_cmd
  640. {
  641.  my $ftp = shift;
  642.  my $cmd = uc shift;
  643.  my $ok = 1;
  644.  my $where = delete ${*$ftp}{'net_ftp_rest'} || 0;
  645.  
  646.  if(${*$ftp}{'net_ftp_passive'} &&
  647.      !defined ${*$ftp}{'net_ftp_pasv'} &&
  648.      !defined ${*$ftp}{'net_ftp_port'})
  649.   {
  650.    my $data = undef;
  651.  
  652.    $ok = defined $ftp->pasv;
  653.    $ok = $ftp->_REST($where)
  654.     if $ok && $where;
  655.  
  656.    if($ok)
  657.     {
  658.      $ftp->command($cmd,@_);
  659.      $data = $ftp->_dataconn();
  660.      $ok = CMD_INFO == $ftp->response();
  661.     }
  662.    return $ok ? $data
  663.               : ($data->_close, undef)[1];
  664.   }
  665.  
  666.  $ok = $ftp->port
  667.     unless (defined ${*$ftp}{'net_ftp_port'} ||
  668.             defined ${*$ftp}{'net_ftp_pasv'});
  669.  
  670.  $ok = $ftp->_REST($where)
  671.     if $ok && $where;
  672.  
  673.  return undef
  674.     unless $ok;
  675.  
  676.  $ftp->command($cmd,@_);
  677.  
  678.  return 1
  679.     if(defined ${*$ftp}{'net_ftp_pasv'});
  680.  
  681.  $ok = CMD_INFO == $ftp->response();
  682.  
  683.  return $ok 
  684.     unless exists ${*$ftp}{'net_ftp_intern_port'};
  685.  
  686.  return $ftp->_dataconn()
  687.     if $ok;
  688.  
  689.  close(delete ${*$ftp}{'net_ftp_listen'});
  690.  
  691.  return undef;
  692. }
  693.  
  694.  
  695. sub debug_text { $_[2] =~ /^(pass|resp)/i ? "$1 ....\n" : $_[2]; }
  696.  
  697. sub command
  698. {
  699.  my $ftp = shift;
  700.  
  701.  delete ${*$ftp}{'net_ftp_port'};
  702.  $ftp->SUPER::command(@_);
  703. }
  704.  
  705. sub response
  706. {
  707.  my $ftp = shift;
  708.  my $code = $ftp->SUPER::response();
  709.  
  710.  delete ${*$ftp}{'net_ftp_pasv'}
  711.     if ($code != CMD_MORE && $code != CMD_INFO);
  712.  
  713.  $code;
  714. }
  715.  
  716. sub parse_response
  717. {
  718.  return ($1, $2 eq "-")
  719.     if $_[1] =~ s/^(\d\d\d)(.?)//o;
  720.  
  721.  my $ftp = shift;
  722.  
  723.  return ()
  724.     unless ${*$ftp}{'net_cmd_code'};
  725.  
  726.  (${*$ftp}{'net_cmd_code'},1);
  727. }
  728.  
  729.  
  730. sub pasv_xfer
  731. {
  732.  my($sftp,$sfile,$dftp,$dfile) = @_;
  733.  
  734.  ($dfile = $sfile) =~ s#.*/##
  735.     unless(defined $dfile);
  736.  
  737.  my $port = $sftp->pasv or
  738.     return undef;
  739.  
  740.  unless($dftp->port($port) && $sftp->retr($sfile) && $dftp->stou($dfile))
  741.   {
  742.    $sftp->abort;
  743.    $dftp->abort;
  744.    return undef;
  745.   }
  746.  
  747.  $dftp->pasv_wait($sftp);
  748. }
  749.  
  750. sub pasv_wait
  751. {
  752.  @_ == 2 or croak 'usage: $ftp->pasv_wait(NON_PASV_FTP)';
  753.  
  754.  my($ftp, $non_pasv) = @_;
  755.  my($file,$rin,$rout);
  756.  
  757.  vec($rin,fileno($ftp),1) = 1;
  758.  select($rout=$rin, undef, undef, undef);
  759.  
  760.  $ftp->response();
  761.  $non_pasv->response();
  762.  
  763.  return undef
  764.     unless $ftp->ok() && $non_pasv->ok();
  765.  
  766.  return $1
  767.     if $ftp->message =~ /unique file name:\s*(\S*)\s*\)/;
  768.  
  769.  return $1
  770.     if $non_pasv->message =~ /unique file name:\s*(\S*)\s*\)/;
  771.  
  772.  return 1;
  773. }
  774.  
  775. sub cmd { shift->command(@_)->responce() }
  776.  
  777.  
  778. sub _ABOR { shift->command("ABOR")->response()     == CMD_OK }
  779. sub _CDUP { shift->command("CDUP")->response()     == CMD_OK }
  780. sub _NOOP { shift->command("NOOP")->response()     == CMD_OK }
  781. sub _PASV { shift->command("PASV")->response()     == CMD_OK }
  782. sub _QUIT { shift->command("QUIT")->response()     == CMD_OK }
  783. sub _DELE { shift->command("DELE",@_)->response() == CMD_OK }
  784. sub _CWD  { shift->command("CWD", @_)->response() == CMD_OK }
  785. sub _PORT { shift->command("PORT",@_)->response() == CMD_OK }
  786. sub _RMD  { shift->command("RMD", @_)->response() == CMD_OK }
  787. sub _MKD  { shift->command("MKD", @_)->response() == CMD_OK }
  788. sub _PWD  { shift->command("PWD", @_)->response() == CMD_OK }
  789. sub _TYPE { shift->command("TYPE",@_)->response() == CMD_OK }
  790. sub _RNTO { shift->command("RNTO",@_)->response() == CMD_OK }
  791. sub _ACCT { shift->command("ACCT",@_)->response() == CMD_OK }
  792. sub _RESP { shift->command("RESP",@_)->response() == CMD_OK }
  793. sub _MDTM { shift->command("MDTM",@_)->response() == CMD_OK }
  794. sub _SIZE { shift->command("SIZE",@_)->response() == CMD_OK }
  795. sub _APPE { shift->command("APPE",@_)->response() == CMD_INFO }
  796. sub _LIST { shift->command("LIST",@_)->response() == CMD_INFO }
  797. sub _NLST { shift->command("NLST",@_)->response() == CMD_INFO }
  798. sub _RETR { shift->command("RETR",@_)->response() == CMD_INFO }
  799. sub _STOR { shift->command("STOR",@_)->response() == CMD_INFO }
  800. sub _STOU { shift->command("STOU",@_)->response() == CMD_INFO }
  801. sub _RNFR { shift->command("RNFR",@_)->response() == CMD_MORE }
  802. sub _REST { shift->command("REST",@_)->response() == CMD_MORE }
  803. sub _USER { shift->command("user",@_)->response() } # A certain brain dead firewall :-)
  804. sub _PASS { shift->command("PASS",@_)->response() }
  805. sub _AUTH { shift->command("AUTH",@_)->response() }
  806.  
  807. sub _ALLO { shift->unsupported(@_) }
  808. sub _SMNT { shift->unsupported(@_) }
  809. sub _HELP { shift->unsupported(@_) }
  810. sub _MODE { shift->unsupported(@_) }
  811. sub _SITE { shift->unsupported(@_) }
  812. sub _SYST { shift->unsupported(@_) }
  813. sub _STAT { shift->unsupported(@_) }
  814. sub _STRU { shift->unsupported(@_) }
  815. sub _REIN { shift->unsupported(@_) }
  816.  
  817.  
  818. package Net::FTP::dataconn;
  819.  
  820. use Carp;
  821. use vars qw(@ISA $timeout);
  822. use Net::Cmd;
  823.  
  824. @ISA = qw(IO::Socket::INET);
  825.  
  826. sub abort
  827. {
  828.  my $data = shift;
  829.  my $ftp  = ${*$data}{'net_ftp_cmd'};
  830.  
  831.  $ftp->abort; # this will close me
  832. }
  833.  
  834. sub _close
  835. {
  836.  my $data = shift;
  837.  my $ftp  = ${*$data}{'net_ftp_cmd'};
  838.  
  839.  $data->SUPER::close();
  840.  
  841.  delete ${*$ftp}{'net_ftp_dataconn'}
  842.     if exists ${*$ftp}{'net_ftp_dataconn'} &&
  843.         $data == ${*$ftp}{'net_ftp_dataconn'};
  844. }
  845.  
  846. sub close
  847. {
  848.  my $data = shift;
  849.  my $ftp  = ${*$data}{'net_ftp_cmd'};
  850.  
  851.  $data->_close;
  852.  
  853.  $ftp->response() == CMD_OK &&
  854.     $ftp->message =~ /unique file name:\s*(\S*)\s*\)/ &&
  855.     (${*$ftp}{'net_ftp_unique'} = $1);
  856.  
  857.  $ftp->status == CMD_OK;
  858. }
  859.  
  860. sub _select
  861. {
  862.  my    $data     = shift;
  863.  local *timeout = \$_[0]; shift;
  864.  my    $rw     = shift;
  865.  
  866.  my($rin,$win);
  867.  
  868.  return 1 unless $timeout;
  869.  
  870.  $rin = '';
  871.  vec($rin,fileno($data),1) = 1;
  872.  
  873.  $win = $rw ? undef : $rin;
  874.  $rin = undef unless $rw;
  875.  
  876.  my $nfound = select($rin, $win, undef, $timeout);
  877.  
  878.  croak "select: $!"
  879.     if $nfound < 0;
  880.  
  881.  return $nfound;
  882. }
  883.  
  884. sub can_read
  885. {
  886.  my    $data    = shift;
  887.  local *timeout = \$_[0];
  888.  
  889.  $data->_select($timeout,1);
  890. }
  891.  
  892. sub can_write
  893. {
  894.  my    $data    = shift;
  895.  local *timeout = \$_[0];
  896.  
  897.  $data->_select($timeout,0);
  898. }
  899.  
  900. sub cmd
  901. {
  902.  my $ftp = shift;
  903.  
  904.  ${*$ftp}{'net_ftp_cmd'};
  905. }
  906.  
  907.  
  908. @Net::FTP::L::ISA = qw(Net::FTP::I);
  909. @Net::FTP::E::ISA = qw(Net::FTP::I);
  910.  
  911.  
  912. package Net::FTP::A;
  913.  
  914. use vars qw(@ISA $buf);
  915. use Carp;
  916.  
  917. @ISA = qw(Net::FTP::dataconn);
  918.  
  919. sub read
  920. {
  921.  my    $data     = shift;
  922.  local *buf     = \$_[0]; shift;
  923.  my    $size     = shift || croak 'read($buf,$size,[$offset])';
  924.  my    $offset     = shift || 0;
  925.  my    $timeout = $data->timeout;
  926.  
  927.  croak "Bad offset"
  928.     if($offset < 0);
  929.  
  930.  $offset = length $buf
  931.     if($offset > length $buf);
  932.  
  933.  ${*$data} ||= "";
  934.  my $l = 0;
  935.  
  936.  READ:
  937.   {
  938.    $data->can_read($timeout) or
  939.     croak "Timeout";
  940.  
  941.    my $n = sysread($data, ${*$data}, $size, length ${*$data});
  942.  
  943.    return $n
  944.     unless($n >= 0);
  945.  
  946.    ${*$data} =~ s/(\015)?(?!\012)\Z//so;
  947.    my $lf = $1 || "";
  948.  
  949.    ${*$data} =~ s/\015\012/\n/sgo;
  950.  
  951.    substr($buf,$offset) = ${*$data};
  952.  
  953.    $l += length(${*$data});
  954.    $offset += length(${*$data});
  955.  
  956.    ${*$data} = $lf;
  957.    
  958.    redo READ
  959.      if($l == 0 && $n > 0);
  960.  
  961.    if($n == 0 && $l == 0)
  962.     {
  963.      substr($buf,$offset) = ${*$data};
  964.      ${*$data} = "";
  965.     }
  966.   }
  967.  
  968.  return $l;
  969. }
  970.  
  971. sub write
  972. {
  973.  my    $data     = shift;
  974.  local *buf     = \$_[0]; shift;
  975.  my    $size     = shift || croak 'write($buf,$size,[$timeout])';
  976.  my    $timeout = @_ ? shift : $data->timeout;
  977.  
  978.  $data->can_write($timeout) or
  979.     croak "Timeout";
  980.  
  981.  
  982.  my $tmp;
  983.  ($tmp = $buf) =~ s/(?!\015)\012/\015\012/sg;
  984.  
  985.  my $len = $size + length($tmp) - length($buf);
  986.  my $wrote = syswrite($data, $tmp, $len);
  987.  
  988.  if($wrote >= 0)
  989.   {
  990.    $wrote = $wrote == $len ? $size
  991.                : $len - $wrote
  992.   }
  993.  
  994.  return $wrote;
  995. }
  996.  
  997.  
  998. package Net::FTP::I;
  999.  
  1000. use vars qw(@ISA $buf);
  1001. use Carp;
  1002.  
  1003. @ISA = qw(Net::FTP::dataconn);
  1004.  
  1005. sub read
  1006. {
  1007.  my    $data     = shift;
  1008.  local *buf     = \$_[0]; shift;
  1009.  my    $size    = shift || croak 'read($buf,$size,[$timeout])';
  1010.  my    $timeout = @_ ? shift : $data->timeout;
  1011.  
  1012.  $data->can_read($timeout) or
  1013.     croak "Timeout";
  1014.  
  1015.  my $n = sysread($data, $buf, $size);
  1016.  
  1017.  $n;
  1018. }
  1019.  
  1020. sub write
  1021. {
  1022.  my    $data    = shift;
  1023.  local *buf     = \$_[0]; shift;
  1024.  my    $size    = shift || croak 'write($buf,$size,[$timeout])';
  1025.  my    $timeout = @_ ? shift : $data->timeout;
  1026.  
  1027.  $data->can_write($timeout) or
  1028.     croak "Timeout";
  1029.  
  1030.  syswrite($data, $buf, $size);
  1031. }
  1032.  
  1033.  
  1034. 1;
  1035.  
  1036. __END__
  1037.  
  1038. =head1 NAME
  1039.  
  1040. Net::FTP - FTP Client class
  1041.  
  1042. =head1 SYNOPSIS
  1043.  
  1044.     use Net::FTP;
  1045.     
  1046.     $ftp = Net::FTP->new("some.host.name");
  1047.     $ftp->login("anonymous","me@here.there");
  1048.     $ftp->cwd("/pub");
  1049.     $ftp->get("that.file");
  1050.     $ftp->quit;
  1051.  
  1052. =head1 DESCRIPTION
  1053.  
  1054. C<Net::FTP> is a class implementing a simple FTP client in Perl as
  1055. described in RFC959.  It provides wrappers for a subset of the RFC959
  1056. commands.
  1057.  
  1058. =head1 OVERVIEW
  1059.  
  1060. FTP stands for File Transfer Protocol.  It is a way of transferring
  1061. files between networked machines.  The protocol defines a client
  1062. (whose commands are provided by this module) and a server (not
  1063. implemented in this module).  Communication is always initiated by the
  1064. client, and the server responds with a message and a status code (and
  1065. sometimes with data).
  1066.  
  1067. The FTP protocol allows files to be sent to or fetched from the
  1068. server.  Each transfer involves a B<local file> (on the client) and a
  1069. B<remote file> (on the server).  In this module, the same file name
  1070. will be used for both local and remote if only one is specified.  This
  1071. means that transferring remote file C</path/to/file> will try to put
  1072. that file in C</path/to/file> locally, unless you specify a local file
  1073. name.
  1074.  
  1075. The protocol also defines several standard B<translations> which the
  1076. file can undergo during transfer.  These are ASCII, EBCDIC, binary,
  1077. and byte.  ASCII is the default type, and indicates that the sender of
  1078. files will translate the ends of lines to a standard representation
  1079. which the receiver will then translate back into their local
  1080. representation.  EBCDIC indicates the file being transferred is in
  1081. EBCDIC format.  Binary (also known as image) format sends the data as
  1082. a contiguous bit stream.  Byte format transfers the data as bytes, the
  1083. values of which remain the same regardless of differences in byte size
  1084. between the two machines (in theory - in practice you should only use
  1085. this if you really know what you're doing).
  1086.  
  1087. =head1 CONSTRUCTOR
  1088.  
  1089. =over 4
  1090.  
  1091. =item new (HOST [,OPTIONS])
  1092.  
  1093. This is the constructor for a new Net::FTP object. C<HOST> is the
  1094. name of the remote host to which a FTP connection is required.
  1095.  
  1096. C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
  1097. Possible options are:
  1098.  
  1099. B<Firewall> - The name of a machine which acts as a FTP firewall. This can be
  1100. overridden by an environment variable C<FTP_FIREWALL>. If specified, and the
  1101. given host cannot be directly connected to, then the
  1102. connection is made to the firewall machine and the string C<@hostname> is
  1103. appended to the login identifier. This kind of setup is also refered to
  1104. as a ftp proxy.
  1105.  
  1106. B<Port> - The port number to connect to on the remote machine for the
  1107. FTP connection
  1108.  
  1109. B<Timeout> - Set a timeout value (defaults to 120)
  1110.  
  1111. B<Debug> - debug level (see the debug method in L<Net::Cmd>)
  1112.  
  1113. B<Passive> - If set to I<true> then all data transfers will be done using 
  1114. passive mode. This is required for some I<dumb> servers, and some
  1115. firewall configurations.  This can also be set by the environment
  1116. variable C<FTP_PASSIVE>.
  1117.  
  1118. =back
  1119.  
  1120. =head1 METHODS
  1121.  
  1122. Unless otherwise stated all methods return either a I<true> or I<false>
  1123. value, with I<true> meaning that the operation was a success. When a method
  1124. states that it returns a value, failure will be returned as I<undef> or an
  1125. empty list.
  1126.  
  1127. =over 4
  1128.  
  1129. =item login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
  1130.  
  1131. Log into the remote FTP server with the given login information. If
  1132. no arguments are given then the C<Net::FTP> uses the C<Net::Netrc>
  1133. package to lookup the login information for the connected host.
  1134. If no information is found then a login of I<anonymous> is used.
  1135. If no password is given and the login is I<anonymous> then the users
  1136. Email address will be used for a password.
  1137.  
  1138. If the connection is via a firewall then the C<authorize> method will
  1139. be called with no arguments.
  1140.  
  1141. =item authorize ( [AUTH [, RESP]])
  1142.  
  1143. This is a protocol used by some firewall ftp proxies. It is used
  1144. to authorise the user to send data out.  If both arguments are not specified
  1145. then C<authorize> uses C<Net::Netrc> to do a lookup.
  1146.  
  1147. =item type (TYPE [, ARGS])
  1148.  
  1149. This method will send the TYPE command to the remote FTP server
  1150. to change the type of data transfer. The return value is the previous
  1151. value.
  1152.  
  1153. =item ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS])
  1154.  
  1155. Synonyms for C<type> with the first arguments set correctly
  1156.  
  1157. B<NOTE> ebcdic and byte are not fully supported.
  1158.  
  1159. =item rename ( OLDNAME, NEWNAME )
  1160.  
  1161. Rename a file on the remote FTP server from C<OLDNAME> to C<NEWNAME>. This
  1162. is done by sending the RNFR and RNTO commands.
  1163.  
  1164. =item delete ( FILENAME )
  1165.  
  1166. Send a request to the server to delete C<FILENAME>.
  1167.  
  1168. =item cwd ( [ DIR ] )
  1169.  
  1170. Attempt to change directory to the directory given in C<$dir>.  If
  1171. C<$dir> is C<"..">, the FTP C<CDUP> command is used to attempt to
  1172. move up one directory. If no directory is given then an attempt is made
  1173. to change the directory to the root directory.
  1174.  
  1175. =item cdup ()
  1176.  
  1177. Change directory to the parent of the current directory.
  1178.  
  1179. =item pwd ()
  1180.  
  1181. Returns the full pathname of the current directory.
  1182.  
  1183. =item rmdir ( DIR )
  1184.  
  1185. Remove the directory with the name C<DIR>.
  1186.  
  1187. =item mkdir ( DIR [, RECURSE ])
  1188.  
  1189. Create a new directory with the name C<DIR>. If C<RECURSE> is I<true> then
  1190. C<mkdir> will attempt to create all the directories in the given path.
  1191.  
  1192. Returns the full pathname to the new directory.
  1193.  
  1194. =item ls ( [ DIR ] )
  1195.  
  1196. Get a directory listing of C<DIR>, or the current directory.
  1197.  
  1198. Returns a reference to a list of lines returned from the server.
  1199.  
  1200. =item dir ( [ DIR ] )
  1201.  
  1202. Get a directory listing of C<DIR>, or the current directory in long format.
  1203.  
  1204. Returns a reference to a list of lines returned from the server.
  1205.  
  1206. =item get ( REMOTE_FILE [, LOCAL_FILE ] )
  1207.  
  1208. Get C<REMOTE_FILE> from the server and store locally. C<LOCAL_FILE> may be
  1209. a filename or a filehandle. If not specified the the file will be stored in
  1210. the current directory with the same leafname as the remote file.
  1211.  
  1212. If C<WHERE> is specified, continue transfer of the remote file
  1213. from this point.
  1214.  
  1215. Returns C<LOCAL_FILE>, or the generated local file name if C<LOCAL_FILE>
  1216. is not given.
  1217.  
  1218. =item put ( LOCAL_FILE [, REMOTE_FILE ] )
  1219.  
  1220. Put a file on the remote server. C<LOCAL_FILE> may be a name or a filehandle.
  1221. If C<LOCAL_FILE> is a filehandle then C<REMOTE_FILE> must be specified. If
  1222. C<REMOTE_FILE> is not specified then the file will be stored in the current
  1223. directory with the same leafname as C<LOCAL_FILE>.
  1224.  
  1225. Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
  1226. is not given.
  1227.  
  1228. =item put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
  1229.  
  1230. Same as put but uses the C<STOU> command.
  1231.  
  1232. Returns the name of the file on the server.
  1233.  
  1234. =item append ( LOCAL_FILE [, REMOTE_FILE ] )
  1235.  
  1236. Same as put but appends to the file on the remote server.
  1237.  
  1238. Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
  1239. is not given.
  1240.  
  1241. =item unique_name ()
  1242.  
  1243. Returns the name of the last file stored on the server using the
  1244. C<STOU> command.
  1245.  
  1246. =item mdtm ( FILE )
  1247.  
  1248. Returns the I<modification time> of the given file
  1249.  
  1250. =item size ( FILE )
  1251.  
  1252. Returns the size in bytes for the given file.
  1253.  
  1254. =back
  1255.  
  1256. The following methods can return different results depending on
  1257. how they are called. If the user explicitly calls either
  1258. of the C<pasv> or C<port> methods then these methods will
  1259. return a I<true> or I<false> value. If the user does not
  1260. call either of these methods then the result will be a
  1261. reference to a C<Net::FTP::dataconn> based object.
  1262.  
  1263. =over 4
  1264.  
  1265. =item nlst ( [ DIR ] )
  1266.  
  1267. Send a C<NLST> command to the server, with an optional parameter.
  1268.  
  1269. =item list ( [ DIR ] )
  1270.  
  1271. Same as C<nlst> but using the C<LIST> command
  1272.  
  1273. =item retr ( FILE )
  1274.  
  1275. Begin the retrieval of a file called C<FILE> from the remote server.
  1276.  
  1277. =item stor ( FILE )
  1278.  
  1279. Tell the server that you wish to store a file. C<FILE> is the
  1280. name of the new file that should be created.
  1281.  
  1282. =item stou ( FILE )
  1283.  
  1284. Same as C<stor> but using the C<STOU> command. The name of the unique
  1285. file which was created on the server will be available via the C<unique_name>
  1286. method after the data connection has been closed.
  1287.  
  1288. =item appe ( FILE )
  1289.  
  1290. Tell the server that we want to append some data to the end of a file
  1291. called C<FILE>. If this file does not exist then create it.
  1292.  
  1293. =back
  1294.  
  1295. If for some reason you want to have complete control over the data connection,
  1296. this includes generating it and calling the C<response> method when required,
  1297. then the user can use these methods to do so.
  1298.  
  1299. However calling these methods only affects the use of the methods above that
  1300. can return a data connection. They have no effect on methods C<get>, C<put>,
  1301. C<put_unique> and those that do not require data connections.
  1302.  
  1303. =over 4
  1304.  
  1305. =item port ( [ PORT ] )
  1306.  
  1307. Send a C<PORT> command to the server. If C<PORT> is specified then it is sent
  1308. to the server. If not the a listen socket is created and the correct information
  1309. sent to the server.
  1310.  
  1311. =item pasv ()
  1312.  
  1313. Tell the server to go into passive mode. Returns the text that represents the
  1314. port on which the server is listening, this text is in a suitable form to
  1315. sent to another ftp server using the C<port> method.
  1316.  
  1317. =back
  1318.  
  1319. The following methods can be used to transfer files between two remote
  1320. servers, providing that these two servers can connect directly to each other.
  1321.  
  1322. =over 4
  1323.  
  1324. =item pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
  1325.  
  1326. This method will do a file transfer between two remote ftp servers. If
  1327. C<DEST_FILE> is omitted then the leaf name of C<SRC_FILE> will be used.
  1328.  
  1329. =item pasv_wait ( NON_PASV_SERVER )
  1330.  
  1331. This method can be used to wait for a transfer to complete between a passive
  1332. server and a non-passive server. The method should be called on the passive
  1333. server with the C<Net::FTP> object for the non-passive server passed as an
  1334. argument.
  1335.  
  1336. =item abort ()
  1337.  
  1338. Abort the current data transfer.
  1339.  
  1340. =item quit ()
  1341.  
  1342. Send the QUIT command to the remote FTP server and close the socket connection.
  1343.  
  1344. =back
  1345.  
  1346. =head2 Methods for the adventurous
  1347.  
  1348. C<Net::FTP> inherits from C<Net::Cmd> so methods defined in C<Net::Cmd> may
  1349. be used to send commands to the remote FTP server.
  1350.  
  1351. =over 4
  1352.  
  1353. =item quot (CMD [,ARGS])
  1354.  
  1355. Send a command, that Net::FTP does not directly support, to the remote
  1356. server and wait for a response.
  1357.  
  1358. Returns most significant digit of the response code.
  1359.  
  1360. B<WARNING> This call should only be used on commands that do not require
  1361. data connections. Misuse of this method can hang the connection.
  1362.  
  1363. =back
  1364.  
  1365. =head1 THE dataconn CLASS
  1366.  
  1367. Some of the methods defined in C<Net::FTP> return an object which will
  1368. be derived from this class.The dataconn class itself is derived from
  1369. the C<IO::Socket::INET> class, so any normal IO operations can be performed.
  1370. However the following methods are defined in the dataconn class and IO should
  1371. be performed using these.
  1372.  
  1373. =over 4
  1374.  
  1375. =item read ( BUFFER, SIZE [, TIMEOUT ] )
  1376.  
  1377. Read C<SIZE> bytes of data from the server and place it into C<BUFFER>, also
  1378. performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
  1379. given the the timeout value from the command connection will be used.
  1380.  
  1381. Returns the number of bytes read before any <CRLF> translation.
  1382.  
  1383. =item write ( BUFFER, SIZE [, TIMEOUT ] )
  1384.  
  1385. Write C<SIZE> bytes of data from C<BUFFER> to the server, also
  1386. performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
  1387. given the the timeout value from the command connection will be used.
  1388.  
  1389. Returns the number of bytes written before any <CRLF> translation.
  1390.  
  1391. =item abort ()
  1392.  
  1393. Abort the current data transfer.
  1394.  
  1395. =item close ()
  1396.  
  1397. Close the data connection and get a response from the FTP server. Returns
  1398. I<true> if the connection was closed successfully and the first digit of
  1399. the response from the server was a '2'.
  1400.  
  1401. =back
  1402.  
  1403. =head1 UNIMPLEMENTED
  1404.  
  1405. The following RFC959 commands have not been implemented:
  1406.  
  1407. =over 4
  1408.  
  1409. =item B<ALLO>
  1410.  
  1411. Allocates storage for the file to be transferred.
  1412.  
  1413. =item B<SMNT>
  1414.  
  1415. Mount a different file system structure without changing login or
  1416. accounting information.
  1417.  
  1418. =item B<HELP>
  1419.  
  1420. Ask the server for "helpful information" (that's what the RFC says) on
  1421. the commands it accepts.
  1422.  
  1423. =item B<MODE>
  1424.  
  1425. Specifies transfer mode (stream, block or compressed) for file to be
  1426. transferred.
  1427.  
  1428. =item B<SITE>
  1429.  
  1430. Request remote server site parameters.
  1431.  
  1432. =item B<SYST>
  1433.  
  1434. Request remote server system identification.
  1435.  
  1436. =item B<STAT>
  1437.  
  1438. Request remote server status.
  1439.  
  1440. =item B<STRU>
  1441.  
  1442. Specifies file structure for file to be transferred.
  1443.  
  1444. =item B<REIN>
  1445.  
  1446. Reinitialize the connection, flushing all I/O and account information.
  1447.  
  1448. =back
  1449.  
  1450. =head1 REPORTING BUGS
  1451.  
  1452. When reporting bugs/problems please include as much information as possible.
  1453. It may be difficult for me to reproduce the problem as almost every setup
  1454. is different.
  1455.  
  1456. A small script which yields the problem will probably be of help. It would
  1457. also be useful if this script was run with the extra options C<Debug => 1>
  1458. passed to the constructor, and the output sent with the bug report. If you
  1459. cannot include a small script then please include a Debug trace from a
  1460. run of your program which does yield the problem.
  1461.  
  1462. =head1 AUTHOR
  1463.  
  1464. Graham Barr <gbarr@ti.com>
  1465.  
  1466. =head1 SEE ALSO
  1467.  
  1468. L<Net::Netrc>
  1469. L<Net::Cmd>
  1470.  
  1471. ftp(1), ftpd(8), RFC 959
  1472. http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
  1473.  
  1474. =head1 CREDITS
  1475.  
  1476. Henry Gabryjelski <henryg@WPI.EDU> - for the suggestion of creating directories
  1477. recursively.
  1478.  
  1479. Nathan Torkington <gnat@frii.com> - for some input on the documentation.
  1480.  
  1481. Roderick Schertler <roderick@gate.net> - for various inputs
  1482.  
  1483. =head1 COPYRIGHT
  1484.  
  1485. Copyright (c) 1995-1997 Graham Barr. All rights reserved.
  1486. This program is free software; you can redistribute it and/or modify it
  1487. under the same terms as Perl itself.
  1488.  
  1489. =cut
  1490.